public class Solution915 {
    public int partitionDisjoint(int[] nums) {
        int[] a=new int[nums.length];
        int[] b=new int[nums.length];
        a[0]=nums[0];
        for (int i=1;i<nums.length;i++){
            a[i]=Math.max(a[i-1],nums[i]);
        }
        b[nums.length-1]=nums[nums.length-1];
        for (int i=nums.length-2;i>=0;i--){
            b[i]=Math.min(b[i+1],nums[i]);
        }
        for (int i=0;i<nums.length-1;i++){
            if (a[i]<=b[i+1]){
                return i+1;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(new Solution915().partitionDisjoint(new int[]{5,0,3,8,6}));
    }
}
